package com.era.act.adm;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.era.entity.Admin;
import com.era.srv.AdminSrv;

public class LoginAction extends ActionSupport implements ModelDriven<Admin>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Admin admin = new Admin();
	private AdminSrv adminSer;
	public Admin getAdmin() {
		return admin;
	}
	public void setAdmin(Admin admin) {
		this.admin = admin;
	}
	public AdminSrv getAdminSer() {
		return adminSer;
	}
	public void setAdminSer(AdminSrv adminSer) {
		this.adminSer = adminSer;
	}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		System.out.println("111111");
		if(admin.getAdminName() != null){
		System.out.println(admin.getAdminName());
		if(adminSer.checkLogin(admin)){
			HttpSession session = ServletActionContext.getRequest()
					.getSession();
			session.setAttribute("adminLogin", admin.getAdminName());
			return SUCCESS;
		}
		}
		return ERROR;
	}
	public Admin getModel() {
		// TODO Auto-generated method stub
		return admin;
	}
	

}
